Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ASCII-1498] add dependency list test for the serverless binary #24770

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions cmd/serverless/dependency_list_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build test && linux

package main

import (
"fmt"
"os"
"os/exec"
"runtime"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

const erroMsg = `
The %s_dependencies_%s.txt file is out of date.
Update the file locally with this content:
%s
`

func buildDependencyList() (string, error) {
run := "go"
GustavoCaso marked this conversation as resolved.
Show resolved Hide resolved
arg0 := "list"
arg1 := "-f"
arg2 := `"{{ join .Deps "\n"}}"`
arg3 := "-tags"
arg4 := "serverless,otlp"
arg5 := "github.com/DataDog/datadog-agent/cmd/serverless"
cmd := exec.Command(run, arg0, arg1, arg2, arg3, arg4, arg5)

stdout, err := cmd.Output()
return string(stdout), err
}

// This test is here to add friction to the process of adding dependencies to the serverless binary.
// If you are adding a dependency to the serverless binary, you must update the dependencies.txt file.
// Same for when you remove a dependency.
// Having this test also allow us to better track additions and removals of dependencies for the serverless binary.
func TestImportPackage(t *testing.T) {
dependencyList, err := buildDependencyList()
assert.NoError(t, err)
file := fmt.Sprintf("%s_dependencies_%s.txt", runtime.GOOS, runtime.GOARCH)

data, err := os.ReadFile(file)
assert.NoError(t, err)

cleanDependencyList := strings.TrimLeft(dependencyList, "\"")
cleanDependencyList = strings.TrimRight(cleanDependencyList, "\"\n")
cleanDependencyList += "\n"
assert.Equal(t, string(data), cleanDependencyList, fmt.Sprintf(erroMsg, runtime.GOOS, runtime.GOARCH, cleanDependencyList))
}
Loading
Loading