Skip to content

Commit

Permalink
fixes unit test build failure by introducing buildEnv and buildExecSt…
Browse files Browse the repository at this point in the history
…mts from binaryConfigs

attempts to ignore ALL intellij files this time
renames free freeFunc to deferFree deferredFreeFn for a more clear api
bumps beskar-ostree go version to match others
  • Loading branch information
Kyle Ishie committed Jan 12, 2024
1 parent 4320e9c commit 3158651
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 44 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ jobs:

release-beskar-ostree:
name: release beskar-ostree
needs: lint
needs: [lint, tests]
runs-on: ubuntu-22.04
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.20'
go-version: '1.21'
- uses: actions/checkout@v3
- name: Release beskar-ostree image
run: ./scripts/mage ci:image ghcr.io/ctrliq/beskar-ostree:${{ github.ref_name }} "${{ github.actor }}" "${{ secrets.GITHUB_TOKEN }}"
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ build/output
vendor
go.work.sum

.idea

*/.idea

internal/plugins/ostree/pkg/libostree/testdata
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/go.imports.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions build/mage/test.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package mage

import "C"
import (
"context"
"fmt"
"strings"

"dagger.io/dagger"
"fmt"
"github.com/magefile/mage/mg"
"strings"
)

type Test mg.Namespace
Expand All @@ -29,6 +29,16 @@ func (Test) Unit(ctx context.Context) error {
WithWorkdir("/src").
With(goCache(client))

for _, config := range binaries {
for key, value := range config.buildEnv {
unitTest = unitTest.WithEnvVariable(key, value)
}

for _, execStmt := range config.buildExecStmts {
unitTest = unitTest.WithExec(execStmt)
}
}

unitTest = unitTest.WithExec([]string{
"go", "test", "-v", "-count=1", "./...",
})
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/pluginsrv/webhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func IsTLSMiddleware(next http.Handler) http.Handler {

func (wh *webHandler[H]) event(w http.ResponseWriter, r *http.Request) {
if wh.manager == nil {
w.WriteHeader(http.StatusInternalServerError)
w.WriteHeader(http.StatusNotImplemented)
return
}

Expand Down
14 changes: 7 additions & 7 deletions internal/plugins/ostree/pkg/libostree/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import "unsafe"

// Option defines an option for pulling ostree repos.
// It is used to build a *C.GVariant via a *C.GVariantBuilder.
// free is an optional function that frees the memory allocated by the option. free may be called more than once.
// deferFree is an optional function that frees the memory allocated by the option. deferFree may be called more than once.
type (
Option func(builder *C.GVariantBuilder, free freeFunc)
freeFunc func(...unsafe.Pointer)
Option func(builder *C.GVariantBuilder, deferFree deferredFreeFn)
deferredFreeFn func(...unsafe.Pointer)
)

// ToGVariant converts the given Options to a GVariant using a GVaraintBuilder.
Expand All @@ -35,12 +35,12 @@ func toGVariant(opts ...Option) *C.GVariant {

// Collect pointers to free later
var toFree []unsafe.Pointer
freeFn := func(ptrs ...unsafe.Pointer) {
deferFreeFn := func(ptrs ...unsafe.Pointer) {
toFree = append(toFree, ptrs...)
}

for _, opt := range opts {
opt(&builder, freeFn)
opt(&builder, deferFreeFn)
}
defer func() {
for i := 0; i < len(toFree); i++ {
Expand All @@ -58,9 +58,9 @@ func gVariantBuilderAddVariant(builder *C.GVariantBuilder, key *C.gchar, variant

// NoGPGVerify sets the gpg-verify option to false in the pull options.
func NoGPGVerify() Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
key := C.CString("gpg-verify")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand Down
40 changes: 20 additions & 20 deletions internal/plugins/ostree/pkg/libostree/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ const (

// Flags adds the given flags to the pull options.
func Flags(flags FlagSet) Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
key := C.CString("flags")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand All @@ -90,12 +90,12 @@ func Flags(flags FlagSet) Option {
// Refs adds the given refs to the pull options.
// When pulling refs from a remote, only the specified refs will be pulled.
func Refs(refs ...string) Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
cRefs := C.MakeRefArray(C.int(len(refs)))
free(unsafe.Pointer(cRefs))
deferFree(unsafe.Pointer(cRefs))
for i := 0; i < len(refs); i++ {
cRef := C.CString(refs[i])
free(unsafe.Pointer(cRef))
deferFree(unsafe.Pointer(cRef))
C.AppendRef(cRefs, C.int(i), cRef)
}
C.g_variant_builder_add_refs(
Expand All @@ -107,9 +107,9 @@ func Refs(refs ...string) Option {

// NoGPGVerifySummary sets the gpg-verify-summary option to false in the pull options.
func NoGPGVerifySummary() Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
key := C.CString("gpg-verify-summary")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand All @@ -121,13 +121,13 @@ func NoGPGVerifySummary() Option {
// Depth sets the depth option to the given value in the pull options.
// How far in the history to traverse; default is 0, -1 means infinite
func Depth(depth int) Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
// 0 is the default depth so there is no need to add it to the builder.
if depth != 0 {
return
}
key := C.CString("depth")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand All @@ -139,9 +139,9 @@ func Depth(depth int) Option {
// DisableStaticDelta sets the disable-static-deltas option to true in the pull options.
// Do not use static deltas.
func DisableStaticDelta() Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
key := C.CString("disable-static-deltas")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand All @@ -153,9 +153,9 @@ func DisableStaticDelta() Option {
// RequireStaticDelta sets the require-static-deltas option to true in the pull options.
// Require static deltas.
func RequireStaticDelta() Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
key := C.CString("require-static-deltas")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand All @@ -167,9 +167,9 @@ func RequireStaticDelta() Option {
// DryRun sets the dry-run option to true in the pull options.
// Only print information on what will be downloaded (requires static deltas).
func DryRun() Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
key := C.CString("dry-run")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand All @@ -181,16 +181,16 @@ func DryRun() Option {
// AppendUserAgent sets the append-user-agent option to the given value in the pull options.
// Additional string to append to the user agent.
func AppendUserAgent(appendUserAgent string) Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
// "" is the default so there is no need to add it to the builder.
if appendUserAgent == "" {
return
}

key := C.CString("append-user-agent")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
cAppendUserAgent := C.CString(appendUserAgent)
free(unsafe.Pointer(cAppendUserAgent))
deferFree(unsafe.Pointer(cAppendUserAgent))
gVariantBuilderAddVariant(
builder,
key,
Expand All @@ -202,9 +202,9 @@ func AppendUserAgent(appendUserAgent string) Option {
// NetworkRetries sets the n-network-retries option to the given value in the pull options.
// Number of times to retry each download on receiving.
func NetworkRetries(n int) Option {
return func(builder *C.GVariantBuilder, free freeFunc) {
return func(builder *C.GVariantBuilder, deferFree deferredFreeFn) {
key := C.CString("n-network-retries")
free(unsafe.Pointer(key))
deferFree(unsafe.Pointer(key))
gVariantBuilderAddVariant(
builder,
key,
Expand Down
11 changes: 1 addition & 10 deletions internal/plugins/static/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (p *Plugin) Start(transport http.RoundTripper, _ *mtls.CAPEM, beskarMeta *g
p.config.Router.Route(
"/artifacts/static/api/v1",
func(r chi.Router) {
r.Use(p.apiMiddleware)
r.Use(pluginsrv.IsTLSMiddleware)
r.Mount("/", apiv1.NewHTTPRouter(
p,
httpcodec.NewDefaultCodecs(nil),
Expand All @@ -146,12 +146,3 @@ func (p *Plugin) Context() context.Context {
func (p *Plugin) RepositoryManager() *repository.Manager[*staticrepository.Handler] {
return p.repositoryManager
}

func (p *Plugin) apiMiddleware(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if !pluginsrv.IsTLS(w, r) {
return
}
next.ServeHTTP(w, r)
})
}

0 comments on commit 3158651

Please sign in to comment.