@@ -16,6 +16,7 @@ package main
1616
1717import (
1818 "context"
19+ "log/slog"
1920 "testing"
2021)
2122
@@ -91,4 +92,50 @@ func TestRun(t *testing.T) {
9192 }
9293 })
9394 }
95+ }
96+
97+ func TestRunCLI (t * testing.T ) {
98+ tests := []struct {
99+ name string
100+ args []string
101+ wantCode int
102+ }{
103+ {
104+ name : "success" ,
105+ args : []string {"librariangen" , "build" },
106+ wantCode : 0 ,
107+ },
108+ {
109+ name : "failure" ,
110+ args : []string {"librariangen" , "foo" },
111+ wantCode : 1 ,
112+ },
113+ }
114+ for _ , tt := range tests {
115+ t .Run (tt .name , func (t * testing.T ) {
116+ if gotCode := runCLI (tt .args ); gotCode != tt .wantCode {
117+ t .Errorf ("runCLI() = %v, want %v" , gotCode , tt .wantCode )
118+ }
119+ })
120+ }
121+ }
122+
123+ func TestParseLogLevel (t * testing.T ) {
124+ tests := []struct {
125+ name string
126+ level string
127+ want slog.Level
128+ }{
129+ {"default" , "" , slog .LevelInfo },
130+ {"debug" , "debug" , slog .LevelDebug },
131+ {"quiet" , "quiet" , slog .LevelError + 1 },
132+ {"invalid" , "foo" , slog .LevelInfo },
133+ }
134+ for _ , tt := range tests {
135+ t .Run (tt .name , func (t * testing.T ) {
136+ if got := parseLogLevel (tt .level ); got != tt .want {
137+ t .Errorf ("parseLogLevel() = %v, want %v" , got , tt .want )
138+ }
139+ })
140+ }
94141}
0 commit comments