Skip to content

Commit

Permalink
remove: assemblyscript
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Nov 28, 2023
1 parent 4fe9186 commit 99bfa62
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 388 deletions.
6 changes: 2 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ archives:
<<: *archive_defaults
wrap_in_directory: false
format: zip

# https://goreleaser.com/customization/aur/
aurs:
-
homepage: "https://github.com/fastly/cli"
- homepage: "https://github.com/fastly/cli"
description: "A CLI for interacting with the Fastly platform"
maintainers:
- 'oss@fastly.com'
Expand Down Expand Up @@ -183,6 +181,6 @@ changelog:
# - --label=created={{ time "2006-01-02T15:04:05Z07:00" }}
# - --label=revision={{ .FullCommit }}
# - --label=licenses=Apache-2.0
# dockerfile: Dockerfile-assemblyscript
# dockerfile: Dockerfile-node
# - <<: *build_opts
# dockerfile: Dockerfile-rust
3 changes: 1 addition & 2 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ Some integration tests aren't run outside of the CI environment, to enable these
The available environment variables are:

- `TEST_COMPUTE_INIT`: runs `TestInit`.
- `TEST_COMPUTE_BUILD`: runs `TestBuildRust`, `TestBuildAssemblyScript` and `TestBuildJavaScript`.
- `TEST_COMPUTE_BUILD`: runs `TestBuildRust`, `TestBuildJavaScript`, `TestBuildGo`.
- `TEST_COMPUTE_BUILD_RUST`: runs `TestBuildRust`.
- `TEST_COMPUTE_BUILD_ASSEMBLYSCRIPT`: runs `TestBuildAssemblyScript`.
- `TEST_COMPUTE_BUILD_JAVASCRIPT`: runs `TestBuildJavaScript`.
- `TEST_COMPUTE_DEPLOY`: runs `TestDeploy`.

Expand Down
6 changes: 0 additions & 6 deletions pkg/commands/compute/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -678,12 +678,6 @@ func identifyToolchain(c *BuildCommand) (string, error) {
func language(toolchain, manifestFilename string, c *BuildCommand, in io.Reader, out io.Writer, spinner text.Spinner) (*Language, error) {
var language *Language
switch toolchain {
case "assemblyscript":
language = NewLanguage(&LanguageOptions{
Name: "assemblyscript",
SourceDirectory: AsSourceDirectory,
Toolchain: NewAssemblyScript(c, in, manifestFilename, out, spinner),
})
case "go":
language = NewLanguage(&LanguageOptions{
Name: "go",
Expand Down
195 changes: 0 additions & 195 deletions pkg/commands/compute/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,201 +640,6 @@ func TestBuildJavaScript(t *testing.T) {
}
}

func TestBuildAssemblyScript(t *testing.T) {
if os.Getenv("TEST_COMPUTE_BUILD_ASSEMBLYSCRIPT") == "" && os.Getenv("TEST_COMPUTE_BUILD") == "" {
t.Log("skipping test")
t.Skip("Set TEST_COMPUTE_BUILD to run this test")
}

args := testutil.Args

scenarios := []struct {
name string
args []string
fastlyManifest string
wantError string
wantRemediationError string
wantOutput []string
npmInstall bool
}{
{
name: "no fastly.toml manifest",
args: args("compute build"),
wantError: "error reading fastly.toml",
wantRemediationError: "Run `fastly compute init` to ensure a correctly configured manifest.",
},
{
name: "empty language",
args: args("compute build"),
fastlyManifest: `
manifest_version = 2
name = "test"`,
wantError: "language cannot be empty, please provide a language",
},
{
name: "unknown language",
args: args("compute build"),
fastlyManifest: `
manifest_version = 2
name = "test"
language = "foobar"`,
wantError: "unsupported language foobar",
},
// The following test validates that the project compiles successfully even
// though the fastly.toml manifest has no build script. There should be a
// default build script inserted.
//
// NOTE: This test passes --verbose so we can validate specific outputs.
{
name: "build script inserted dynamically when missing",
args: args("compute build --verbose"),
fastlyManifest: `
manifest_version = 2
name = "test"
language = "assemblyscript"`,
wantOutput: []string{
"No [scripts.build] found in fastly.toml.", // requires --verbose
"The following default build command for",
"npm exec -- asc",
},
},
{
name: "build error",
args: args("compute build"),
fastlyManifest: `
manifest_version = 2
name = "test"
language = "assemblyscript"
[scripts]
build = "echo no compilation happening"`,
wantRemediationError: compute.DefaultBuildErrorRemediation,
},
// NOTE: This test passes --verbose so we can validate specific outputs.
{
name: "successful build",
args: args("compute build --verbose"),
fastlyManifest: fmt.Sprintf(`
manifest_version = 2
name = "test"
language = "assemblyscript"
[scripts]
build = "%s"`, compute.AsDefaultBuildCommand),
wantOutput: []string{
"Creating ./bin directory (for Wasm binary)",
"Built package",
},
npmInstall: true,
},
}
for testcaseIdx := range scenarios {
testcase := &scenarios[testcaseIdx]
t.Run(testcase.name, func(t *testing.T) {
// We're going to chdir to a build environment,
// so save the PWD to return to, afterwards.
pwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}

wasmtoolsBinName := "wasm-tools"

// Windows was having issues when trying to move a tmpBin file (which
// represents the latest binary downloaded from GitHub) to binPath (which
// represents the existing binary installed on a user's machine).
//
// The problem was, for the sake of the tests, I just create one file
// `wasmtoolsBinName` and used that for both `tmpBin` and `binPath` and
// this works fine on *nix systems. But once Windows did `os.Rename()` and
// move tmpBin to binPath it would no longer be able to set permissions on
// the binPath because it didn't think the file existed any more. My guess
// is that moving a file over itself causes Windows to remove the file.
//
// So to work around that issue I just create two separate files because
// in reality that's what the CLI will be dealing with. I only used one
// file for the sake of test case convenience (which ironically became
// very INCONVENIENT when the tests started unexpectedly failing on
// Windows and caused me a long time debugging).
latestDownloaded := wasmtoolsBinName + "-latest-downloaded"

// Create test environment
rootdir := testutil.NewEnv(testutil.EnvOpts{
T: t,
Copy: []testutil.FileIO{
{Src: filepath.Join("testdata", "build", "assemblyscript", "package.json"), Dst: "package.json"},
{Src: filepath.Join("testdata", "build", "assemblyscript", "assembly", "index.ts"), Dst: filepath.Join("assembly", "index.ts")},
},
Write: []testutil.FileIO{
{Src: `#!/usr/bin/env bash
echo wasm-tools 1.0.4`, Dst: wasmtoolsBinName, Executable: true},
{Src: `#!/usr/bin/env bash
echo wasm-tools 2.0.0`, Dst: latestDownloaded, Executable: true},
{Src: testcase.fastlyManifest, Dst: manifest.Filename},
},
})
defer os.RemoveAll(rootdir)
wasmtoolsBinPath := filepath.Join(rootdir, wasmtoolsBinName)

// Before running the test, chdir into the build environment.
// When we're done, chdir back to our original location.
// This is so we can reliably copy the testdata/ fixtures.
if err := os.Chdir(rootdir); err != nil {
t.Fatal(err)
}
defer func() {
_ = os.Chdir(pwd)
}()

// NOTE: We only want to run `npm install` for the success case.
if testcase.npmInstall {
// gosec flagged this:
// G204 (CWE-78): Subprocess launched with variable
// Disabling as we control this command.
// #nosec
// nosemgrep
cmd := exec.Command("npm", "install")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

err = cmd.Run()
if err != nil {
t.Fatal(err)
}
}

var stdout threadsafe.Buffer
app.Init = func(_ []string, _ io.Reader) (*global.Data, error) {
opts := testutil.MockGlobalData(testcase.args, &stdout)
opts.Versioners = global.Versioners{
WasmTools: mock.AssetVersioner{
AssetVersion: "1.2.3",
BinaryFilename: wasmtoolsBinName,
DownloadOK: true,
DownloadedFile: latestDownloaded,
InstallFilePath: wasmtoolsBinPath, // avoid overwriting developer's actual wasm-tools install
},
}
return opts, nil
}
err = app.Run(testcase.args, nil)

t.Log(stdout.String())

testutil.AssertRemediationErrorContains(t, err, testcase.wantRemediationError)

// NOTE: Some errors we want to assert only the remediation.
// e.g. a 'stat' error isn't the same across operating systems/platforms.
if testcase.wantError != "" {
testutil.AssertErrorContains(t, err, testcase.wantError)
}
for _, s := range testcase.wantOutput {
testutil.AssertStringContains(t, stdout.String(), s)
}
})
}
}

// NOTE: TestBuildOther also validates the post_build settings.
func TestBuildOther(t *testing.T) {
args := testutil.Args
Expand Down

This file was deleted.

23 changes: 0 additions & 23 deletions pkg/commands/compute/testdata/build/assemblyscript/package.json

This file was deleted.

7 changes: 3 additions & 4 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,9 @@ type Profile struct {

// StarterKitLanguages represents language specific starter kits.
type StarterKitLanguages struct {
AssemblyScript []StarterKit `toml:"assemblyscript"`
Go []StarterKit `toml:"go"`
JavaScript []StarterKit `toml:"javascript"`
Rust []StarterKit `toml:"rust"`
Go []StarterKit `toml:"go"`
JavaScript []StarterKit `toml:"javascript"`
Rust []StarterKit `toml:"rust"`
}

// StarterKit represents starter kit specific configuration.
Expand Down
Loading

0 comments on commit 99bfa62

Please sign in to comment.