diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml new file mode 100644 index 0000000..98962ed --- /dev/null +++ b/.gitea/workflows/ci.yaml @@ -0,0 +1,27 @@ +name: CI + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: '1.21' + + - name: Run tests + run: go test -v ./... + + - name: Build + run: go build -o ci-test . + + - name: Run binary + run: ./ci-test diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0d006dd --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module ci-test + +go 1.21 diff --git a/main.go b/main.go new file mode 100644 index 0000000..96d474e --- /dev/null +++ b/main.go @@ -0,0 +1,16 @@ +package main + +import "fmt" + +func Add(a, b int) int { + return a + b +} + +func Greet(name string) string { + return fmt.Sprintf("Hello, %s!", name) +} + +func main() { + fmt.Println(Greet("CI/CD")) + fmt.Println("2 + 3 =", Add(2, 3)) +} diff --git a/main_test.go b/main_test.go new file mode 100644 index 0000000..7c63a62 --- /dev/null +++ b/main_test.go @@ -0,0 +1,28 @@ +package main + +import "testing" + +func TestAdd(t *testing.T) { + tests := []struct { + a, b, want int + }{ + {2, 3, 5}, + {0, 0, 0}, + {-1, 1, 0}, + {100, 200, 300}, + } + for _, tt := range tests { + got := Add(tt.a, tt.b) + if got != tt.want { + t.Errorf("Add(%d, %d) = %d, want %d", tt.a, tt.b, got, tt.want) + } + } +} + +func TestGreet(t *testing.T) { + got := Greet("World") + want := "Hello, World!" + if got != want { + t.Errorf("Greet(World) = %q, want %q", got, want) + } +}