mirror of
https://github.com/coder/coder.git
synced 2025-03-14 10:09:57 +00:00
- https://github.com/coder/coder/pull/15504 broke CI on main because of the aforementioned issue, this also fixes the test failure.
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package examples_test
|
|
|
|
import (
|
|
"archive/tar"
|
|
"bytes"
|
|
"errors"
|
|
"io"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/coder/coder/v2/examples"
|
|
)
|
|
|
|
func TestTemplate(t *testing.T) {
|
|
t.Parallel()
|
|
list, err := examples.List()
|
|
require.NoError(t, err, "error listing examples, run \"make gen\" to ensure examples are up to date")
|
|
require.NotEmpty(t, list)
|
|
for _, eg := range list {
|
|
eg := eg
|
|
t.Run(eg.ID, func(t *testing.T) {
|
|
t.Parallel()
|
|
assert.NotEmpty(t, eg.ID, "example ID should not be empty")
|
|
assert.NotEmpty(t, eg.URL, "example URL should not be empty")
|
|
assert.NotEmpty(t, eg.Name, "example name should not be empty")
|
|
assert.NotEmpty(t, eg.Description, "example description should not be empty")
|
|
assert.NotEmpty(t, eg.Markdown, "example markdown should not be empty")
|
|
assert.NotNil(t, eg.Tags, "example tags should not be nil, should be empty array if no tags")
|
|
_, err := examples.Archive(eg.ID)
|
|
assert.NoError(t, err, "error archiving example")
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestSubdirs(t *testing.T) {
|
|
t.Parallel()
|
|
tarData, err := examples.Archive("docker")
|
|
require.NoError(t, err)
|
|
|
|
tarReader := tar.NewReader(bytes.NewReader(tarData))
|
|
entryPaths := make(map[byte][]string)
|
|
for {
|
|
header, err := tarReader.Next()
|
|
if errors.Is(err, io.EOF) {
|
|
break
|
|
}
|
|
require.NoError(t, err)
|
|
|
|
entryPaths[header.Typeflag] = append(entryPaths[header.Typeflag], header.Name)
|
|
}
|
|
|
|
require.Subset(t, entryPaths[tar.TypeReg], []string{"README.md", "main.tf"})
|
|
}
|