Skip to content

[TT-14429]: added fail test for bloblang #7027

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kofoworola
Copy link
Contributor

@kofoworola kofoworola commented Apr 22, 2025

User description

TT-14429
Summary add test cases for bloblang
Type Sub-task Sub-task
Status In Code Review
Points N/A
Labels -

Description

TT-14429

Related Issue

Motivation and Context

How This Has Been Tested

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring or add test (improvements in base code or adds test coverage to functionality)

Checklist

  • I ensured that the documentation is up to date
  • I explained why this PR updates go.mod in detail with reasoning why it's required
  • I would like a code coverage CI quality gate exception and have explained why

PR Type

Tests


Description

  • Add test for invalid Bloblang expression in streaming pipeline

  • Introduce invalid Bloblang config template for NATS input

  • Ensure WebSocket connection fails with invalid Bloblang

  • Maintain test isolation with container cleanup


Changes walkthrough 📝

Relevant files
Tests
mw_streaming_test.go
Add test for invalid Bloblang in streaming pipeline           

gateway/mw_streaming_test.go

  • Added bentoNatsTemplateInvalidBloblang with an invalid Bloblang
    expression
  • Introduced TestStreamingInvalidBloblang to verify error handling on
    invalid Bloblang
  • Ensured test cleans up NATS container and test server resources
  • Confirmed WebSocket connection fails as expected with invalid config
  • +71/-0   

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • @buger
    Copy link
    Member

    buger commented Apr 22, 2025

    I'm a bot and I 👍 this PR title. 🤖

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Test Coverage

    The new test TestStreamingInvalidBloblang is designed to verify behavior when an invalid Bloblang expression is used. Ensure that this test reliably fails for the correct reason and that error assertions are specific enough to catch only the intended failure mode.

    func TestStreamingInvalidBloblang(t *testing.T) {
    	ctx := context.Background()
    
    	natsContainer, err := natscon.Run(
    		ctx,
    		"nats:2.9",
    		testcontainers.WithWaitStrategy(wait.ForAll(
    			wait.ForLog("Server is ready"),
    			wait.ForListeningPort("4222/tcp"),
    		).WithDeadline(30*time.Second)))
    	require.NoError(t, err)
    	t.Cleanup(func() {
    		natsContainer.Terminate(ctx)
    	})
    
    	//skip if is dynamic, does not work
    
    	configSubject := "test"
    
    	connectionStr, err := natsContainer.ConnectionString(ctx)
    	assert.NoError(t, err)
    	streamConfig := fmt.Sprintf(bentoNatsTemplateInvalidBloblang, configSubject, connectionStr)
    
    	ts := StartTest(func(globalConf *config.Config) {
    		globalConf.Streaming.Enabled = true
    	})
    	t.Cleanup(func() {
    		ts.Close()
    	})
    	//t.Cleanup(func() { ts.Close() })
    	apiName := "test-api"
    	if err = setUpStreamAPI(ts, apiName, streamConfig); err != nil {
    		t.Fatal(err)
    	}
    
    	const totalMessages = 3
    
    	dialer := websocket.Dialer{
    		HandshakeTimeout: 1 * time.Second,
    		TLSClientConfig:  &tls.Config{InsecureSkipVerify: true},
    	}
    
    	wsURL := strings.Replace(ts.URL, "http", "ws", 1) + fmt.Sprintf("/%s/get/ws", apiName)
    
    	_, _, err = dialer.Dial(wsURL, nil)
    	assert.Error(t, err)
    }

    Copy link
    Contributor

    PR Code Suggestions ✨

    No code suggestions found for the PR.

    Copy link
    Contributor

    API Changes

    no api changes detected

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    3 participants