Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/cli/lock/key_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package lock

import (
"encoding/base64"
"testing"
)

func TestGenerateLicenseKey(t *testing.T) {
key, err := GenerateLicenseKey()
if err != nil {
t.Fatalf("GenerateLicenseKey() error = %v", err)
}
if key == "" {
t.Error("GenerateLicenseKey() returned empty string")
}

// Verify it is valid base64
_, err = base64.StdEncoding.DecodeString(key)
if err != nil {
t.Errorf("GenerateLicenseKey() returned invalid base64: %v", err)
}
}
122 changes: 122 additions & 0 deletions src/cli/tweet/future_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package tweet

import (
"testing"
)

func TestHandleTweetTime(t *testing.T) {
tests := []struct {
name string
input string
wantHours int
wantMinutes int
wantErr bool
}{
{
name: "hours and minutes",
input: "2h3m",
wantHours: 2,
wantMinutes: 3,
wantErr: false,
},
{
name: "only hours",
input: "5h",
wantHours: 5,
wantMinutes: 0,
wantErr: false,
},
{
name: "only minutes",
input: "30m",
wantHours: 0,
wantMinutes: 30,
wantErr: false,
},
{
name: "empty string",
input: "",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
{
name: "invalid format garbage",
input: "abc",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
{
name: "missing suffix",
input: "2h3",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
{
name: "invalid number",
input: "xh",
wantHours: 0,
wantMinutes: 0,
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotHours, gotMinutes, err := handleTweetTime(tt.input)
if (err != nil) != tt.wantErr {
t.Errorf("handleTweetTime() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotHours != tt.wantHours {
t.Errorf("handleTweetTime() gotHours = %v, want %v", gotHours, tt.wantHours)
}
if gotMinutes != tt.wantMinutes {
t.Errorf("handleTweetTime() gotMinutes = %v, want %v", gotMinutes, tt.wantMinutes)
}
})
}
}

func TestHandleFutureTweetArgs(t *testing.T) {
tests := []struct {
name string
args []string
wantTweet string
wantTime string
wantErr bool
}{
{
name: "valid args",
args: []string{"x", "f", "hello world", "2h"},
wantTweet: "hello world",
wantTime: "2h",
wantErr: false,
},
{
name: "not enough args",
args: []string{"x", "f"},
wantTweet: "",
wantTime: "",
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotTweet, gotTime, err := handleFutureTweetArgs(tt.args)
if (err != nil) != tt.wantErr {
t.Errorf("handleFutureTweetArgs() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotTweet != tt.wantTweet {
t.Errorf("handleFutureTweetArgs() gotTweet = %v, want %v", gotTweet, tt.wantTweet)
}
if gotTime != tt.wantTime {
t.Errorf("handleFutureTweetArgs() gotTime = %v, want %v", gotTime, tt.wantTime)
}
})
}
}
Loading