|
| 1 | +package version |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | +) |
| 6 | + |
| 7 | +func TestNewInfo(t *testing.T) { |
| 8 | + info := NewInfo("TestApp") |
| 9 | + if info.Application != "TestApp" { |
| 10 | + t.Errorf("Expected application name 'TestApp', got '%s'", info.Application) |
| 11 | + } |
| 12 | +} |
| 13 | + |
| 14 | +func TestInfoString(t *testing.T) { |
| 15 | + info := &Info{ |
| 16 | + Application: "TestApp", |
| 17 | + VersionString: "1.0.0", |
| 18 | + Commit: "abc123", |
| 19 | + Date: "2023-01-01", |
| 20 | + } |
| 21 | + expected := "TestApp Version: 1.0.0 Commit: abc123 Date: 2023-01-01" |
| 22 | + if got := info.String(); got != expected { |
| 23 | + t.Errorf("Expected '%s', got '%s'", expected, got) |
| 24 | + } |
| 25 | +} |
| 26 | + |
| 27 | +func TestInfoShortString(t *testing.T) { |
| 28 | + tests := []struct { |
| 29 | + name string |
| 30 | + info Info |
| 31 | + expected string |
| 32 | + }{ |
| 33 | + { |
| 34 | + name: "full info", |
| 35 | + info: Info{ |
| 36 | + Application: "TestApp", |
| 37 | + VersionString: "1.0.0", |
| 38 | + Commit: "abc123", |
| 39 | + Date: "2023-01-01T12:00:00Z", |
| 40 | + }, |
| 41 | + expected: "TestApp 1.0.0 (abc123 2023-01-01)", |
| 42 | + }, |
| 43 | + { |
| 44 | + name: "no commit", |
| 45 | + info: Info{ |
| 46 | + Application: "TestApp", |
| 47 | + VersionString: "1.0.0", |
| 48 | + Date: "2023-01-01T12:00:00Z", |
| 49 | + }, |
| 50 | + expected: "TestApp 1.0.0 (2023-01-01)", |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "no date", |
| 54 | + info: Info{ |
| 55 | + Application: "TestApp", |
| 56 | + VersionString: "1.0.0", |
| 57 | + Commit: "abc123", |
| 58 | + }, |
| 59 | + expected: "TestApp 1.0.0 (abc123)", |
| 60 | + }, |
| 61 | + { |
| 62 | + name: "version only", |
| 63 | + info: Info{ |
| 64 | + Application: "TestApp", |
| 65 | + VersionString: "1.0.0", |
| 66 | + }, |
| 67 | + expected: "TestApp 1.0.0", |
| 68 | + }, |
| 69 | + } |
| 70 | + |
| 71 | + for _, tt := range tests { |
| 72 | + t.Run(tt.name, func(t *testing.T) { |
| 73 | + if got := tt.info.ShortString(); got != tt.expected { |
| 74 | + t.Errorf("Expected '%s', got '%s'", tt.expected, got) |
| 75 | + } |
| 76 | + }) |
| 77 | + } |
| 78 | +} |
0 commit comments