Skip to content

Commit

Permalink
Move trace test to a separate file. (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
kislaykishore authored Sep 27, 2024
1 parent 4f40a8f commit 6bb4e4c
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 156 deletions.
156 changes: 0 additions & 156 deletions internal/fs/wrappers/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,11 @@
package wrappers

import (
"context"
"fmt"
"syscall"
"testing"

"github.com/jacobsa/fuse/fuseops"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.opentelemetry.io/otel/trace"
)

func TestFsErrStrAndCategory(t *testing.T) {
Expand Down Expand Up @@ -105,152 +98,3 @@ func TestFsErrStrAndCategory(t *testing.T) {
})
}
}

func newInMemoryExporter(t *testing.T) *tracetest.InMemoryExporter {
t.Helper()
ex := tracetest.NewInMemoryExporter()
t.Cleanup(func() {
ex.Reset()
})
otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSyncer(ex)))
return ex
}

type dummyFS struct{}

func (d dummyFS) StatFS(_ context.Context, _ *fuseops.StatFSOp) error {
return nil
}

func (d dummyFS) LookUpInode(_ context.Context, _ *fuseops.LookUpInodeOp) error {
return nil
}

func (d dummyFS) GetInodeAttributes(_ context.Context, _ *fuseops.GetInodeAttributesOp) error {
return nil
}

func (d dummyFS) SetInodeAttributes(_ context.Context, _ *fuseops.SetInodeAttributesOp) error {
return nil
}

func (d dummyFS) ForgetInode(_ context.Context, _ *fuseops.ForgetInodeOp) error {
return nil
}

func (d dummyFS) BatchForget(_ context.Context, _ *fuseops.BatchForgetOp) error {
return nil
}

func (d dummyFS) MkDir(_ context.Context, _ *fuseops.MkDirOp) error {
return nil
}

func (d dummyFS) MkNode(_ context.Context, _ *fuseops.MkNodeOp) error {
return nil
}

func (d dummyFS) CreateFile(_ context.Context, _ *fuseops.CreateFileOp) error {
return nil
}

func (d dummyFS) CreateLink(_ context.Context, _ *fuseops.CreateLinkOp) error {
return nil
}

func (d dummyFS) CreateSymlink(_ context.Context, _ *fuseops.CreateSymlinkOp) error {
return nil
}

func (d dummyFS) Rename(_ context.Context, _ *fuseops.RenameOp) error {
return nil
}

func (d dummyFS) RmDir(_ context.Context, _ *fuseops.RmDirOp) error {
return nil
}

func (d dummyFS) Unlink(_ context.Context, _ *fuseops.UnlinkOp) error {
return nil
}

func (d dummyFS) OpenDir(_ context.Context, _ *fuseops.OpenDirOp) error {
return nil
}

func (d dummyFS) ReadDir(_ context.Context, _ *fuseops.ReadDirOp) error {
return nil
}

func (d dummyFS) ReleaseDirHandle(_ context.Context, _ *fuseops.ReleaseDirHandleOp) error {
return nil
}

func (d dummyFS) OpenFile(_ context.Context, _ *fuseops.OpenFileOp) error {
return nil
}

func (d dummyFS) ReadFile(_ context.Context, _ *fuseops.ReadFileOp) error {
return nil
}

func (d dummyFS) WriteFile(_ context.Context, _ *fuseops.WriteFileOp) error {
return nil
}

func (d dummyFS) SyncFile(_ context.Context, _ *fuseops.SyncFileOp) error {
return nil
}

func (d dummyFS) FlushFile(_ context.Context, _ *fuseops.FlushFileOp) error {
return nil
}

func (d dummyFS) ReleaseFileHandle(_ context.Context, _ *fuseops.ReleaseFileHandleOp) error {
return nil
}

func (d dummyFS) ReadSymlink(_ context.Context, _ *fuseops.ReadSymlinkOp) error {
return nil
}

func (d dummyFS) RemoveXattr(_ context.Context, _ *fuseops.RemoveXattrOp) error {
return nil
}

func (d dummyFS) GetXattr(_ context.Context, _ *fuseops.GetXattrOp) error {
return nil
}

func (d dummyFS) ListXattr(_ context.Context, _ *fuseops.ListXattrOp) error {
return nil
}

func (d dummyFS) SetXattr(_ context.Context, _ *fuseops.SetXattrOp) error {
return nil
}

func (d dummyFS) Fallocate(_ context.Context, _ *fuseops.FallocateOp) error {
return nil
}

func (d dummyFS) Destroy() {}

func TestSpanCreation(t *testing.T) {
ex := newInMemoryExporter(t)
t.Cleanup(func() {
ex.Reset()
})
m := monitoring{
wrapped: dummyFS{},
tracer: otel.Tracer("test"),
}

err := m.StatFS(context.Background(), nil)
require.NoError(t, err)

ss := ex.GetSpans()
require.Len(t, ss, 1)
assert.Equal(t, "StatFS", ss[0].Name)
assert.Equal(t, trace.SpanKindServer, ss[0].SpanKind)
}
177 changes: 177 additions & 0 deletions internal/fs/wrappers/tracing_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package wrappers

import (
"context"
"testing"

"github.com/jacobsa/fuse/fuseops"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/otel"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
"go.opentelemetry.io/otel/sdk/trace/tracetest"
"go.opentelemetry.io/otel/trace"
)

func newInMemoryExporter(t *testing.T) *tracetest.InMemoryExporter {
t.Helper()
ex := tracetest.NewInMemoryExporter()
t.Cleanup(func() {
ex.Reset()
})
otel.SetTracerProvider(sdktrace.NewTracerProvider(sdktrace.WithSyncer(ex)))
return ex
}

type dummyFS struct{}

func (d dummyFS) StatFS(_ context.Context, _ *fuseops.StatFSOp) error {
return nil
}

func (d dummyFS) LookUpInode(_ context.Context, _ *fuseops.LookUpInodeOp) error {
return nil
}

func (d dummyFS) GetInodeAttributes(_ context.Context, _ *fuseops.GetInodeAttributesOp) error {
return nil
}

func (d dummyFS) SetInodeAttributes(_ context.Context, _ *fuseops.SetInodeAttributesOp) error {
return nil
}

func (d dummyFS) ForgetInode(_ context.Context, _ *fuseops.ForgetInodeOp) error {
return nil
}

func (d dummyFS) BatchForget(_ context.Context, _ *fuseops.BatchForgetOp) error {
return nil
}

func (d dummyFS) MkDir(_ context.Context, _ *fuseops.MkDirOp) error {
return nil
}

func (d dummyFS) MkNode(_ context.Context, _ *fuseops.MkNodeOp) error {
return nil
}

func (d dummyFS) CreateFile(_ context.Context, _ *fuseops.CreateFileOp) error {
return nil
}

func (d dummyFS) CreateLink(_ context.Context, _ *fuseops.CreateLinkOp) error {
return nil
}

func (d dummyFS) CreateSymlink(_ context.Context, _ *fuseops.CreateSymlinkOp) error {
return nil
}

func (d dummyFS) Rename(_ context.Context, _ *fuseops.RenameOp) error {
return nil
}

func (d dummyFS) RmDir(_ context.Context, _ *fuseops.RmDirOp) error {
return nil
}

func (d dummyFS) Unlink(_ context.Context, _ *fuseops.UnlinkOp) error {
return nil
}

func (d dummyFS) OpenDir(_ context.Context, _ *fuseops.OpenDirOp) error {
return nil
}

func (d dummyFS) ReadDir(_ context.Context, _ *fuseops.ReadDirOp) error {
return nil
}

func (d dummyFS) ReleaseDirHandle(_ context.Context, _ *fuseops.ReleaseDirHandleOp) error {
return nil
}

func (d dummyFS) OpenFile(_ context.Context, _ *fuseops.OpenFileOp) error {
return nil
}

func (d dummyFS) ReadFile(_ context.Context, _ *fuseops.ReadFileOp) error {
return nil
}

func (d dummyFS) WriteFile(_ context.Context, _ *fuseops.WriteFileOp) error {
return nil
}

func (d dummyFS) SyncFile(_ context.Context, _ *fuseops.SyncFileOp) error {
return nil
}

func (d dummyFS) FlushFile(_ context.Context, _ *fuseops.FlushFileOp) error {
return nil
}

func (d dummyFS) ReleaseFileHandle(_ context.Context, _ *fuseops.ReleaseFileHandleOp) error {
return nil
}

func (d dummyFS) ReadSymlink(_ context.Context, _ *fuseops.ReadSymlinkOp) error {
return nil
}

func (d dummyFS) RemoveXattr(_ context.Context, _ *fuseops.RemoveXattrOp) error {
return nil
}

func (d dummyFS) GetXattr(_ context.Context, _ *fuseops.GetXattrOp) error {
return nil
}

func (d dummyFS) ListXattr(_ context.Context, _ *fuseops.ListXattrOp) error {
return nil
}

func (d dummyFS) SetXattr(_ context.Context, _ *fuseops.SetXattrOp) error {
return nil
}

func (d dummyFS) Fallocate(_ context.Context, _ *fuseops.FallocateOp) error {
return nil
}

func (d dummyFS) Destroy() {}

func TestSpanCreation(t *testing.T) {
ex := newInMemoryExporter(t)
t.Cleanup(func() {
ex.Reset()
})
m := monitoring{
wrapped: dummyFS{},
tracer: otel.Tracer("test"),
}

err := m.StatFS(context.Background(), nil)
require.NoError(t, err)

ss := ex.GetSpans()
require.Len(t, ss, 1)
assert.Equal(t, "StatFS", ss[0].Name)
assert.Equal(t, trace.SpanKindServer, ss[0].SpanKind)
}

0 comments on commit 6bb4e4c

Please sign in to comment.