(t *testing.T)
| 3 | import "testing" |
| 4 | |
| 5 | func TestFullVersion(t *testing.T) { |
| 6 | tests := []struct { |
| 7 | name string |
| 8 | version string |
| 9 | commit string |
| 10 | dirty string |
| 11 | expected string |
| 12 | }{ |
| 13 | { |
| 14 | name: "release build", |
| 15 | version: "1.0.0", |
| 16 | commit: "unknown", |
| 17 | dirty: "", |
| 18 | expected: "1.0.0", |
| 19 | }, |
| 20 | { |
| 21 | name: "dev build with commit", |
| 22 | version: "0.0.3", |
| 23 | commit: "abc1234", |
| 24 | dirty: "", |
| 25 | expected: "0.0.3-abc1234", |
| 26 | }, |
| 27 | { |
| 28 | name: "dev build with dirty tree", |
| 29 | version: "0.0.3", |
| 30 | commit: "abc1234", |
| 31 | dirty: "true", |
| 32 | expected: "0.0.3-abc1234*", |
| 33 | }, |
| 34 | { |
| 35 | name: "dev build with long commit hash", |
| 36 | version: "0.0.3", |
| 37 | commit: "abc1234567890", |
| 38 | dirty: "false", |
| 39 | expected: "0.0.3-abc1234", |
| 40 | }, |
| 41 | { |
| 42 | name: "empty commit", |
| 43 | version: "0.0.3", |
| 44 | commit: "", |
| 45 | dirty: "", |
| 46 | expected: "0.0.3", |
| 47 | }, |
| 48 | } |
| 49 | |
| 50 | for _, tt := range tests { |
| 51 | t.Run(tt.name, func(t *testing.T) { |
| 52 | origVersion := Version |
| 53 | origCommit := GitCommit |
| 54 | origDirty := GitDirty |
| 55 | defer func() { |
| 56 | Version = origVersion |
| 57 | GitCommit = origCommit |
| 58 | GitDirty = origDirty |
| 59 | }() |
| 60 | |
| 61 | Version = tt.version |
| 62 | GitCommit = tt.commit |
nothing calls this directly
no test coverage detected