platforms_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package ast
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. )
  7. func TestPlatformParsing(t *testing.T) {
  8. tests := []struct {
  9. Input string
  10. ExpectedOS string
  11. ExpectedArch string
  12. Error string
  13. }{
  14. {Input: "windows", ExpectedOS: "windows", ExpectedArch: ""},
  15. {Input: "linux", ExpectedOS: "linux", ExpectedArch: ""},
  16. {Input: "darwin", ExpectedOS: "darwin", ExpectedArch: ""},
  17. {Input: "386", ExpectedOS: "", ExpectedArch: "386"},
  18. {Input: "amd64", ExpectedOS: "", ExpectedArch: "amd64"},
  19. {Input: "arm64", ExpectedOS: "", ExpectedArch: "arm64"},
  20. {Input: "windows/386", ExpectedOS: "windows", ExpectedArch: "386"},
  21. {Input: "windows/amd64", ExpectedOS: "windows", ExpectedArch: "amd64"},
  22. {Input: "windows/arm64", ExpectedOS: "windows", ExpectedArch: "arm64"},
  23. {Input: "invalid", Error: `invalid platform "invalid"`},
  24. {Input: "invalid/invalid", Error: `invalid platform "invalid/invalid"`},
  25. {Input: "windows/invalid", Error: `invalid platform "windows/invalid"`},
  26. {Input: "invalid/amd64", Error: `invalid platform "invalid/amd64"`},
  27. }
  28. for _, test := range tests {
  29. t.Run(test.Input, func(t *testing.T) {
  30. var p Platform
  31. err := p.parsePlatform(test.Input)
  32. if test.Error != "" {
  33. require.Error(t, err)
  34. assert.Equal(t, test.Error, err.Error())
  35. } else {
  36. require.NoError(t, err)
  37. assert.Equal(t, test.ExpectedOS, p.OS)
  38. assert.Equal(t, test.ExpectedArch, p.Arch)
  39. }
  40. })
  41. }
  42. }